// const setting = require('./setting/setting.js');

App({
	onLaunch: function (options) {
		this.globalData = {};

		// 用于自定义导航栏
		wx.getSystemInfo({
			success: e => {
					this.globalData.statusBarHeight = e.statusBarHeight;
				let capsule = wx.getMenuButtonBoundingClientRect();
				if (capsule) { 
					this.globalData.customBarHeight = capsule.bottom + capsule.top - e.statusBarHeight;
					this.globalData.capsule = capsule;
				} else {
					this.globalData.customBarHeight = e.statusBarHeight + 50;
				
				} 
			}
		});


		const openid = wx.getStorageSync('openId')
		if(!openid){
			this.info()
		}

	
	}, 
	info() {
		const appid = 'wx1c2d7bc048d96638'
		const secret = 'b47b7a18fcfe956702ee23b54d2ef543'

		wx.getUserInfo({
			//成功后会返回
			success: (res) => {
				console.log(res);
				// 把你的用户信息存到一个变量中方便下面使用
				let userInfo = res.userInfo
				//获取openId（需要code来换取）这是用户的唯一标识符
				// 获取code值
				wx.login({
					//成功放回
					success: (res) => {
						console.log(res);
						let code = res.code
						// 通过code换取openId
						wx.request({
							url: `https://api.weixin.qq.com/sns/jscode2session?appid=${appid}&secret=${secret}&js_code=${code}&grant_type=authorization_code`,
							success: (res) => {
								console.log(res);
								userInfo.openid = res.data.openid
								wx.setStorageSync('userInfo', userInfo)
								wx.setStorageSync('openId', res.data.openid)
								console.log(userInfo.openid);
							}
						})
					}
				})

			}
		})
	}
	 
})